﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ProjectSchedule.Common;
using System.Threading;

namespace ProjectSchedule
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Boolean _createdOnce;
            Mutex _instance = new Mutex(true, "MutexName", out _createdOnce);
            if (_createdOnce)
            {
                log4net.Config.XmlConfigurator.Configure();

                Application.ThreadException += new ThreadExceptionEventHandler((obj, eventArgs) =>
                {
                    LogHelper.Error("未捕获的线程异常：", eventArgs.Exception);
                });

                Logon logon = new Logon();
                if (logon.ShowDialog() == DialogResult.OK)
                {
                    Application.ApplicationExit += new EventHandler((obj, eventArgs) =>
                    {
                        LogHelper.Info("退出应用程序 " +"\r\n");
                    });
                    LogHelper.Info("启动应用程序 ");
                    Application.Run(new MainForm());
                }
                _instance.ReleaseMutex();
            }
            else
            {
                MessageBox.Show("已经启动一个相同的程序，请先退出！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
        }
    }
}
